/**
 * 初始化数据
 * @param {Object} roleCode
 */
function initData(deviceCode){
	$('#selectDeviceCode').val(deviceCode);
	//渲染表格
    var deviceLogColumns = deviceLogList.deviceLogColumnsInit();
    deviceLogList.deviceLogGridInit(deviceLogColumns);
}

/**
 * 下载文件
 * @param {Object} id
 */
function download(id){
	window.open($$.restServerUrl + '/rest/IotDeviceLogBusiness/download?id='+id+'124');
}

;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var  deviceLogList = {
        deviceLogColumnsInit:function(){
            return  [
	            {
	            	title: '文件名称',
	                field: 'fileName',
	                width: '400px'
	            },
	            {
	            	title: '创建时间',
	                field: 'createTime',
	                sortable : true
	            },
	            {
	            	title: '操作',
	                field: 'option',
	                width: 200,
                	align: 'center',
                	formatter: function (value, row, index) {
                		return '<a href="javascript:download(\''+row.id+'\');"><div title="点击下载文件"><i class="glyphicon glyphicon-save"></i>下载 </div></a>';
	            	}
               }
            ]
        },
        deviceLogGridInit:function(columns){
            return $("#deviceLogTable").bootstrapTable({
            	method: "post",
                contentType: "application/x-www-form-urlencoded",
                url:$$.restServerUrl + '/bootstrap/basegrid/IotDeviceLogBusiness/list',
                columns: columns,
                undefinedText: '-',
                striped: 'true',
                classes: 'table table-hover qxttable',
                pagination: 'true',
                clickToSelect: true,
                singleSelect: false,
                sidePagination: "server",
                queryParamsType: "page",
                sortSide: 'client',
                sortable: true,
                pageNumber: 1,
                pageSize: 10,
                idField: 'id',
                silentSort: true,
                pageList: [
                    10, 20, 50, 100
                ],
                queryParams: function queryParams(params) {//设置查询参数
                    var args = {};
                    var deviceCode = $('#selectDeviceCode').val();
                    args.c_deviceCode_1 = deviceCode;
                    args.page = params.pageNumber - 1;//params.pageNumber
                    args.pageSize = params.pageSize;//params.pageSize
                    args.isPage = 1;
                    var paramStr = JSON.stringify(args);
                    var param = {
                        params: paramStr
                    };
                    return param;
                }
            });
        }
    };

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = deviceLogList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return deviceLogList;});
    } else {
        !('plugin' in _global) && (_global.deviceLogList = deviceLogList);
    }
}());

